package com.example.spring.jpa.specification;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: orange
 * @create: 2023-07-24 20:11
 * @description:
 */
public class BasicTypeFacade {
    private final Map<String, PredicateGenerate> generateMap = new HashMap<>();

    private final ComplexTypeFacade superFacade = new ComplexTypeFacade(this);

    public BasicTypeFacade() {
        IntegerGenerate integerGenerate = new IntegerGenerate();
        StringGenerate stringGenerate = new StringGenerate();
        ShortGenerate shortGenerate = new ShortGenerate();
        FloatGenerate floatGenerate = new FloatGenerate();
        DoubleGenerate doubleGenerate = new DoubleGenerate();
        ByteGenerate byteGenerate = new ByteGenerate();
        BooleanGenerate booleanGenerate = new BooleanGenerate();
        CharacterGenerate characterGenerate = new CharacterGenerate();
        DateGenerate dateGenerate = new DateGenerate();
        LongGenerate longGenerate = new LongGenerate();
        this.generateMap.put(JavaBasicType.Integer$1.getPackageName(), integerGenerate);
        this.generateMap.put(JavaBasicType.Integer$2.getPackageName(), integerGenerate);
        this.generateMap.put(JavaBasicType.String.getPackageName(), stringGenerate);
        this.generateMap.put(JavaBasicType.Short$1.getPackageName(), shortGenerate);
        this.generateMap.put(JavaBasicType.Short$2.getPackageName(), shortGenerate);
        this.generateMap.put(JavaBasicType.Double$1.getPackageName(), doubleGenerate);
        this.generateMap.put(JavaBasicType.Double$2.getPackageName(), doubleGenerate);
        this.generateMap.put(JavaBasicType.Float$1.getPackageName(), floatGenerate);
        this.generateMap.put(JavaBasicType.Float$2.getPackageName(), floatGenerate);
        this.generateMap.put(JavaBasicType.Byte$1.getPackageName(), byteGenerate);
        this.generateMap.put(JavaBasicType.Byte$2.getPackageName(), byteGenerate);
        this.generateMap.put(JavaBasicType.Boolean$1.getPackageName(), booleanGenerate);
        this.generateMap.put(JavaBasicType.Boolean$2.getPackageName(), booleanGenerate);
        this.generateMap.put(JavaBasicType.Character$1.getPackageName(), characterGenerate);
        this.generateMap.put(JavaBasicType.Character$2.getPackageName(), characterGenerate);
        this.generateMap.put(JavaBasicType.Date.getPackageName(), dateGenerate);
        this.generateMap.put(JavaBasicType.Long$1.getPackageName(), longGenerate);
        this.generateMap.put(JavaBasicType.Long$2.getPackageName(), longGenerate);
    }

    public PredicateGenerate predicateFormTypeName(String typeName) {
        PredicateGenerate generate = generateMap.get(typeName);
        if (generate == null) {
            return superFacade.predicateFormTypeName(typeName);
        }
        return generate;
    }
}
